/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

Ext.QuickTips.init();
var _pageSize = 20;

var fieldName = ['id', 'name','event','detail', 'code', 'time', 'endTime','pointTypeID','status'];
var fieldLabel = ['ID','监测点名称', '事件类型', '事件说明', '所属单位', '发生时间', '结束时间','电压类型','上报状态'];
var fieldType = [];

var saveServlet = '../../servlet/system/ExceptionSave';
var loadServlet = '../../servlet/system/ExceptionLoad';
var deleteServlet = '../../servlet/system/ExceptionDel';
var dbtable = 't_exception';
var theme = '告警';

var _title = currentOrgName + theme + '管理';

var now = new Date();
var beginDate = now.format('Y-m-d');
var endDate = now.add(Date.DAY, -7).format('Y-m-d');

var inputForm = new Ext.FormPanel(
        {
            xtype: 'form',
            id: 'input-form',
            bodyStyle: 'padding:15px;background:transparent',
            frame: true,
            border: false,
            url: saveServlet,
            items: [{
                    name: fieldName[0],
                    xtype: 'textfield',
                    fieldLabel: fieldLabel[0],
                    hidden: true
                },  {
                    name: 'name',
                    xtype: 'textfield',
                    fieldLabel: '监测点名称',
                    allowBlank: false,
                    maxLength: 100,
                    maxLengthText: '不能多于100个字符,1个汉字占用2个字符'
                }, {
                    name: 'event',
                    id: 'event',
                    xtype: 'textfield',
                    fieldLabel: '事件类型',
                    allowBlank: false,
                    maxLength: 20,
                    maxLengthText: '不能多于20个字符,1个汉字占用2个字符'
                }, {
                    name: 'detail',
                    xtype: 'textfield',
                    fieldLabel: '事件说明',
                    width: 150,
                    allowBlank: false,
                    maxLength: 200,
                    maxLengthText: '不能多于200个字符,1个汉字占用2个字符'
                }, {
                    name: 'code',
                    xtype: 'textfield',
                    fieldLabel: '所属单位',
                    width: 150,
                    allowBlank: false,
                    maxLength: 50,
                    maxLengthText: '不能多于50个字符,1个汉字占用2个字符'
                }, {
                    name: 'time',
                    xtype: 'textfield',
                    fieldLabel: '发生时间',
                    width: 150

                }, {
                    name: 'endTime',
                    xtype: 'textfield',
                    fieldLabel: '结束时间',
                    width: 150

                },{
                    name: 'pointTypeID',
                    xtype: 'textfield',
                    fieldLabel: '电压类型',
                    allowBlank: false,
                    maxLength: 20,
                    maxLengthText: '不能多于20个字符,1个汉字占用2个字符'
                }, 
                {
                    name: 'status',
                    xtype: 'textfield',
                    fieldLabel: '上报状态',
                    allowBlank: false,
                    maxLength: 20,
                    maxLengthText: '不能多于20个字符,1个汉字占用2个字符'
                }
            ]
           
        }
);


var checkboxSel = new Ext.grid.CheckboxSelectionModel();
var store;
function buildWindow() {

    store = new Ext.data.JsonStore({
        url: loadServlet,
        root: 'data',
        idProperty: 'id',
        totalProperty: 'count',
        fields: fieldName,
        baseParams: {beginDate: beginDate, endDate: endDate, start: 0, limit: _pageSize}
        , autoLoad: true
    });

    var grid = new Ext.grid.GridPanel({
        title: '告警事件查询统计',
        store: store,
        sm: checkboxSel,
        viewConfig: {
            forceFit: true
        },
        columns: [
            checkboxSel,
            {header: fieldLabel[0], sortable: true, dataIndex: fieldName[0], hidden: true},
            {header: fieldLabel[1], width: 80, sortable: true, dataIndex: fieldName[1]},
            {header: fieldLabel[2], width: 80, sortable: true, dataIndex: fieldName[2]},
            {header: fieldLabel[3], width: 80, sortable: true, dataIndex: fieldName[3]},
            {header: fieldLabel[4], width: 80, sortable: true, dataIndex: fieldName[4]},
            {header: fieldLabel[5], width: 100, sortable: true, dataIndex: fieldName[5], xtype: 'datecolumn', format: 'Y-m-d'},
            {header: fieldLabel[6], width: 100, sortable: true, dataIndex: fieldName[6], xtype: 'datecolumn', format: 'Y-m-d'},
            {header: fieldLabel[7], width: 100, sortable: true, dataIndex: fieldName[7]},
            {header: fieldLabel[8], width: 80, sortable: true, dataIndex: fieldName[8]}
        ],
        //autoExpandColumn: fieldName[2],
        //renderTo: Ext.getBody(),
        //width: 780,
        //height: 590,
        loadMask: true,
        tbar: new Ext.Toolbar([
            
            {
                text: "选择开始日期:", xtype: 'label', style: {marginLeft: '20px'}
            },
            {
                xtype: 'datefield',
                id: 'dateFrom',
                format: 'Y年m月d日',
                width: 150,
                value: now.add(Date.DAY, -7),
                listeners: {
                    select: function(c, date) {
                        beginDate = date.format('Y-m-d');
                        store.baseParams.beginDate = beginDate;
                    }
                }
            },
            '-',
            {
                text: "选择结束日期:", xtype: 'label', style: {marginLeft: '20px'}
            },
            {
                xtype: 'datefield',
                id: 'dateTo',
                format: 'Y年m月d日',
                width: 150,
                value: now,
                listeners: {
                    select: function(c, date) {
                        beginDate = date.format('Y-m-d');
                        store.baseParams.beginDate = beginDate;
                    }
                }
            },
            {
                xtype:'combo',
                width:120,
                fieldLabel: '告警类型选择...',
                mode: 'local',
                value: '合格率异常',
                allowBlank: false,
                //msgTarget: 'side',
                id: 'warnTypeChoose',
                triggerAction: 'all',
                forceSelection:true,
                store: new Ext.data.ArrayStore({
                    fields: [
                    'id',
                    'warnType'
                    ],
                    data: [['0', '合格率异常'],['1', '电压数据缺失'],['2', '电压数据越上限'],['3', '电压数据越下限']]
                }),
                valueField: 'id',
                displayField: 'warnType',
                anchor: '50%'
            },
            {
                xtype: 'button',
                text: '搜索',
                iconCls: 'icon-search',
                width: 60,
                style: {marginLeft: '20px'},
                handler: function() {
                    store.load({params: {start: 0, limit: _pageSize}});
                }
            }
        ]),
        bbar: new Ext.PagingToolbar({
            pageSize: _pageSize,
            store: store,
            displayInfo: true,
            displayMsg: '显示记录：{0} - {1}   总记录：{2}',
            emptyMsg: "目前没有" + theme + '信息'
        })
    });
    //grid.el.center();
    //store.load({params: {start: 0, limit: _pageSize}});

    var applicationUI = new Ext.Viewport({
        layout: "fit",
        items: [
            grid
        ]
    });
}
Ext.onReady(buildWindow);  